package AS_source{
import Components.*;

import flash.events.MouseEvent;

import mx.containers.Accordion;
import mx.containers.ApplicationControlBar;
import mx.containers.Grid;
import mx.containers.GridItem;
import mx.containers.GridRow;
import mx.containers.TabNavigator;
import mx.containers.VBox;
import mx.controls.ComboBox;
import mx.controls.tabBarClasses.Tab;
        public class Driver{
                var tabNavi:TabNavigator;
                var searchNavi:Accordion;
                var rankHelper:RankSearch;
                var mapHelper:MapView;
                var profHelper:ProfSearch;
                var newsupdateHelper:NewsUpdates;
               // var picsupdateHelper:picSearch;
                public function Driver(tabControl:TabNavigator, searchControl:Accordion){
                        tabNavi = tabControl;
                        searchNavi = searchControl;
                        rankHelper = new RankSearch(tabControl,searchControl);
                        mapHelper = new MapView(tabControl,searchControl);
                        profHelper = new ProfSearch(tabControl,searchControl);
                        newsupdateHelper = new NewsUpdates(tabControl,searchControl);
                       // picsupdateHelper =new PicSearch(tabControl,searchControl);
                        this.initHandlers();
                }
                 private function initHandlers():void{
                        tabNavi.addEventListener(MouseEvent.MOUSE_UP , onTabNavClicked,true);
                        var rankSearch:Rank_Search_VBox = Rank_Search_VBox(searchNavi.getChildByName("rankSearch"));
                        //set data provider for rankSearchVBox
                        var controlBar:ApplicationControlBar = ApplicationControlBar(rankSearch.getChildByName("genControlBar"))
                        var genBox:VBox = VBox(controlBar.getChildByName("genVBox"));
                        ComboBox(genBox.getChildByName("genComboBox")).dataProvider = rankHelper.getDataProvider();
                        rankSearch.getChildByName("rankSearchButton").addEventListener(MouseEvent.MOUSE_UP, rankHelper.searchButtonEvt);
                        genBox.getChildByName("genComboBox").addEventListener("change", rankHelper.comboChangeEvt);
                        //ComboBox(rankSearch.getChildByName("genComboBox")).dataProvider = rankHelper.getDataProvider();
                        //set handler for rankSearchVBox search Button. 
                        //set handler for location search button
                        
                        var locSearch:Loc_Search_VBox=Loc_Search_VBox(searchNavi.getChildByName("locSearch"));
                        var localSearchGrid:Grid=Grid(locSearch.getChildByName("localsearchgrid"));
                        var searchgridrow:GridRow=GridRow(localSearchGrid.getChildByName("searchgridrow"));
                        
                        var searchgridItem:GridItem=GridItem(searchgridrow.getChildByName("searchgridItem"));
                        
                        searchgridItem.getChildByName("locsearchButton").addEventListener(MouseEvent.MOUSE_UP, mapHelper.handleFind);
                    
                    //Profile Search Setup
                    	var profSearch:Profile_Search_VBox = Profile_Search_VBox(searchNavi.getChildByName("profSearch"));
                        //set data provider for profSearchVBox
                        var controlBar:ApplicationControlBar = ApplicationControlBar(profSearch.getChildByName("profControlBar"))
                        var genBox:VBox = VBox(controlBar.getChildByName("profVBox"));
                        ComboBox(genBox.getChildByName("profComboBox")).dataProvider = profHelper.getDataProvider();
                        profSearch.getChildByName("profSearchButton").addEventListener(MouseEvent.MOUSE_UP, profHelper.searchButtonEvt);
                        //event handling of the profile search button to also display newsupdates
                        profSearch.getChildByName("profSearchButton").addEventListener(MouseEvent.MOUSE_UP, newsupdateHelper.updatesearchButtonEvt);
                       // profSearch.getChildByName("profSearchButton").addEventListener(MouseEvent.MOUSE_UP, Edumaps.getImages);
                }
                public function getTabNavi():TabNavigator{
                        return tabNavi;
                }
                public function getSearchNavi():Accordion{
                        return searchNavi;
                }
                private function onTabNavClicked(event:MouseEvent):void{
                        //if(tabNavi.selectedIndex.valueOf() == 1){
                        if (event.target is Tab ){
                                        
                                //Alert.show("Selected tabNavi:  " + tabNavi.selectedIndex.valueOf());
                                //Alert.show("searchNavi: " + searchNavi.getChildByName("rankSearch"));
                                /*
                                var tester:VBox = VBox(tabNavi.getChildAt(tabNavi.selectedIndex.valueOf()));
                                var txtBox:Text = Text(tester.getChildByName("textBox"));
                                txtBox.text += "Hello I was clicked" + txtBox;
                                */
                                //Alert.show("Selected object:  " + tester.getChildren());
                                
                        }
                        //}
                
                }       
        }
}
